package com.ljm.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ljm.domain.Book;
import com.ljm.service.IBookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/*第一版本*/
//@RestController
//@RequestMapping("/books")
public class BookController2 {

    @Autowired
    private IBookService iBookService;

    // 增删改查
    @GetMapping
    public List<Book> getAll(){
        return iBookService.list();
    }

    @PostMapping
    public  Boolean save(@RequestBody Book book){
        return iBookService.save(book);
    }

    @PutMapping
    public  Boolean update(@RequestBody Book book){
       return iBookService.updateById(book);
    }

    @DeleteMapping("{id}")
    public Boolean delete(@PathVariable Integer id){
        return  iBookService.removeById(id);
    }

    // 查单个 http://localhost/books/2
    @GetMapping("{id}")
    public Book getById(@PathVariable Integer id){
        return iBookService.getById(id);
    }

    // 分页查询
//    @GetMapping("{currentPage}/{pageSize}")
//    public IPage<Book> getPage(@PathVariable int currentPage,@PathVariable int pageSize){
//        return iBookService.getPage(currentPage,pageSize);
//    }
    @GetMapping("{currentPage}/{pageSize}")
    public IPage<Book> getPage(@PathVariable int currentPage,@PathVariable int pageSize){
        return iBookService.getPage(currentPage,pageSize);
    }
}






















